package com.fjnldx.ks.exception;

import com.fjnldx.ks.pojo.response.Result;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;

import javax.servlet.http.HttpServletRequest;

@ControllerAdvice
public class GlobalExceptionHandler {

    private final Logger logger = LoggerFactory.getLogger(GlobalExceptionHandler.class);

    @ExceptionHandler(value = ProcessException.class)
    public Result defaultErrorHandler(HttpServletRequest req, Exception e) {
        Result result = new Result();//出现异常后返回到前端的信息
        result.setCode(-1);
        result.setMsg("出现了业务异常");
        logger.error("调用失败", e);
        return result;
    }
}
